package app.server.project.main.service.db.dao.user;

import app.server.project.main.service.db.entity.user.UserRaceDetailEntity;
import app.server.project.main.service.db.mapper.user.UserRaceDetailMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【user_info(用户信息表)】的数据库操作Service实现
 * @createDate 2025-01-16 15:25:22
 */
@Repository
@AllArgsConstructor
public class UserRaceDetailDao extends ServiceImpl<UserRaceDetailMapper, UserRaceDetailEntity> {


    private final static String Cache_Name = "app.server.project.main.service.db.dao.UserRaceDetailDao";


    @Cacheable(key = "#userId+':'+#raceId", cacheNames = Cache_Name)
    public List<UserRaceDetailEntity> getLastData(long userId, long pageSize, long pageIndex, int raceId) {
        var ret = new ArrayList<UserRaceDetailEntity>(this.page(Page.of(pageIndex, pageSize),
                        Wrappers.<UserRaceDetailEntity>lambdaQuery()
                                .eq(UserRaceDetailEntity::getRaceId, raceId)
                                .eq(UserRaceDetailEntity::getUserId, userId)
                                .orderByDesc(UserRaceDetailEntity::getId))
                .getRecords());
        ret.forEach(v -> v.setSynDb(true));
        return ret;
    }


    //@CacheEvict(key = "#userId+':'+#pageIndex+':'+#raceId", cacheNames = Cache_Name)
    public void delDetailCache(long userId, long pageIndex, int raceId) {
    }


}




